package com.yfy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yfy.model.entity.User;
import com.yfy.model.mapper.UserMapper;
import com.yfy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @Author yfy2001
 * @date 2022/11/16 9:46
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public void register(User user) {
        user.setCreator("System");
        user.setModifier("System");
        user.setGmtModified(new Date());
        user.setGmtCreated(new Date());
        user.setIsDeleted("N");
        user.setValid(1);
        userMapper.addUser(user);
    }

    @Override
    public PageInfo<User> selectUserWithPage(Integer page, Integer count) {
        PageHelper.startPage(page, count);
        List<User> userList = userMapper.selectUserWithPage();
        PageInfo<User> pageInfo=new PageInfo<>(userList);
        return pageInfo;
    }

    @Override
    public void logicDeletedUser(User user) {
        user.setModifier("admin");
        user.setGmtModified(new Date());
        user.setIsDeleted("Y");
        user.setValid(0);
        userMapper.updateUser(user);
    }

    @Override
    public void unDeletedUser(User user) {
        user.setModifier("admin");
        user.setGmtModified(new Date());
        user.setIsDeleted("N");
        user.setValid(1);
        userMapper.updateUser(user);
    }
}
